home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / gfx / misc / SafeClip.lha / SafeClip / GCC / safeclip.h < prev    next >
C/C++ Source or Header  |  1996-03-29  |  7KB  |  247 lines

  1. /****h* Autodoc/safeclip.h [1.0] *
  2. *  NAME
  3. *    safeclip.h
  4. *  FUNCTION
  5. *    Interface to system rendering routines, but with clipping.
  6. *  AUTHOR
  7. *    Peter Knight: All programming.
  8. *    <pak@star.sr.bham.ac.uk>
  9. *  CREATION DATE
  10. *    24-Mar-96
  11. *  COPYRIGHT
  12. *    No restriction (Public Domain).
  13. *    Use these routines as you wish in your programs (a 
  14. *    mention in the credits would be nice, but it's up to
  15. *    you).
  16. **********
  17. */
  18.  
  19. #include <exec/types.h>
  20. #include <proto/graphics.h>
  21.  
  22. /* Prototypes for functions from safeclip.c */
  23. ULONG SafeInit (ULONG nvertmax);
  24. VOID SafeClose (VOID);
  25. VOID SafeAreaEnd (struct RastPort *rp);
  26. VOID SafeRectFill (struct RastPort *rp, LONG x1, LONG y1, LONG x2, LONG y2);
  27. VOID SafeDraw (struct RastPort *rp, LONG x, LONG y);
  28.  
  29. /****** safeclip.h/SafeSetLimits
  30. * NAME
  31. *   SafeSetLimits
  32. * SYNOPSIS
  33. *        SafeSetLimits (x1, y1, x2, y2)
  34. *   VOID SafeSetLimits (LONG, LONG, LONG, LONG)
  35. * FUNCTION
  36. *   Set limits of clipping rectangle
  37. * INPUTS
  38. *   (x1,y1) - Coordinates of upper left of clipping rectangle
  39. *   (x2,y2) - Coordinates of lower right of clipping rectangle
  40. * RESULTS
  41. * SEE ALSO
  42. */
  43. static __inline VOID
  44. SafeSetLimits (LONG x1, LONG y1, LONG x2, LONG y2)
  45. {
  46.   extern LONG CLP_xmin, CLP_ymin, CLP_xmax, CLP_ymax;
  47.   CLP_xmin = x1;
  48.   CLP_ymin = y1;
  49.   CLP_xmax = x2;
  50.   CLP_ymax = y2;
  51. }
  52. /*********/
  53.  
  54. /****** safeclip.h/SafeAreaDraw
  55. * NAME
  56. *   SafeAreaDraw
  57. * SYNOPSIS
  58. *        SafeAreaDraw (x, y)
  59. *   VOID SafeAreaDraw (LONG, LONG)
  60. * FUNCTION
  61. *   Add a vertex to polygon vertex list.
  62. * INPUTS
  63. *   (x,y) - Coordinates of new vertex
  64. * RESULTS
  65. * SEE ALSO
  66. *   safeclip.c/SafeAreaEnd 
  67. */
  68. static __inline VOID
  69. SafeAreaDraw (LONG x, LONG y)
  70. {
  71.   extern LONG CLP_nvert, CLP_nvertmax, (*CLP_vert)[2];
  72.   if (CLP_nvert < CLP_nvertmax)
  73.     {
  74.       CLP_vert[CLP_nvert][0] = x;
  75.       CLP_vert[CLP_nvert][1] = y;
  76.       CLP_nvert++;
  77.     }
  78. }
  79. /*********/
  80.  
  81. /****** safeclip.h/SafeMove
  82. * NAME
  83. *   SafeMove
  84. * SYNOPSIS
  85. *        SafeMove (x, y)
  86. *   VOID SafeMove (LONG, LONG)
  87. * FUNCTION
  88. *   Move drawing pen to new position.
  89. * INPUTS
  90. *   (x,y) - Coordinates of new point.
  91. * RESULTS
  92. * SEE ALSO
  93. *   safeclip.c/SafeDraw
  94. */
  95. static __inline VOID
  96. SafeMove (LONG x, LONG y)
  97. {
  98.   extern LONG CLP_lastx, CLP_lasty;
  99.   CLP_lastx = x;
  100.   CLP_lasty = y;
  101. }
  102. /*********/
  103.  
  104. /****** safeclip.h/SafeSetRast
  105. * NAME
  106. *   SafeSetRast
  107. * SYNOPSIS
  108. *        SafeSetRast (rp, pen)
  109. *   VOID SafeSetRast (struct RastPort *, UBYTE)
  110. * FUNCTION
  111. *   Set the entire clipping region to a certain colour.
  112. * INPUTS
  113. *   rp - Pointer to RastPort
  114. *   pen - Pen number to fill region with.
  115. * RESULTS
  116. * SEE ALSO
  117. */
  118. static __inline VOID
  119. SafeSetRast (struct RastPort *rp, UBYTE pen)
  120. {
  121.   extern LONG CLP_xmin, CLP_ymin, CLP_xmax, CLP_ymax;
  122.   UBYTE oldPen = rp->FgPen;   /* should use GetAPen() if v39+ */
  123.   SetAPen (rp, pen);
  124.   RectFill (rp, CLP_xmin, CLP_ymin, CLP_xmax, CLP_ymax);
  125.   SetAPen (rp, oldPen);
  126. }
  127. /*********/
  128.  
  129. /****** safeclip.h/SafeWritePixel
  130. * NAME
  131. *   SafeWritePixel
  132. * SYNOPSIS
  133. *        SafeWritePixel (rp, x, y)
  134. *   VOID SafeWritePixel (struct RastPort *, LONG, LONG)
  135. * FUNCTION
  136. *   Set the colour of an individual pixel.
  137. * INPUTS
  138. *   rp - Pointer to RastPort
  139. *   (x,y) - Coordinates of pixel
  140. * RESULTS
  141. * SEE ALSO
  142. */
  143. static __inline VOID
  144. SafeWritePixel (struct RastPort *rp, LONG x, LONG y)
  145. {
  146.   extern LONG CLP_xmin, CLP_xmax, CLP_ymin, CLP_ymax;
  147.   if (x >= CLP_xmin && x <= CLP_xmax && y >= CLP_ymin && y <= CLP_ymax)
  148.     WritePixel (rp, x, y);
  149. }
  150. /*********/
  151.  
  152. /****** safeclip.h/SafeBltBitMapRastPort
  153. * NAME
  154. *   SafeBltBitMapRastPort
  155. * SYNOPSIS
  156. *        SafeBltBitMapRastPort (srcbm, srcx, srcy,
  157. *                               destrp, destx, desty.
  158. *                               sizex, sizey, minterm)
  159. *   VOID SafeBltBitMapRastPort (struct BitMap *, LONG, LONG,
  160. *                               struct RastPort *, LONG, LONG,
  161. *                               LONG, LONG, UBYTE)
  162. * FUNCTION
  163. *   Blit a rectangle region from a BitMap to a RastPort.
  164. * INPUTS
  165. *   srcbm - Pointer to source BitMap
  166. *   (srcx,srcy) - Coordinates of upper left of source rectangle.
  167. *   destrp - Pointer to destination RastPort
  168. *   (destx,desty) - Coordinates of upper left of destination rectangle.
  169. *   sizex, sizey - Size of source rectangle
  170. *   minterm - Minterm for blitter to use during copy
  171. * RESULTS
  172. * SEE ALSO
  173. *   SafeBltMaskBitMapRastPort
  174. */
  175. static __inline VOID
  176. SafeBltBitMapRastPort (struct BitMap *srcbm, LONG srcx, LONG srcy,
  177.                struct RastPort *destrp, LONG destx, LONG desty,
  178.                LONG sizex, LONG sizey, UBYTE minterm)
  179. {
  180.   extern LONG CLP_xmin, CLP_xmax, CLP_ymin, CLP_ymax;
  181.   LONG xlo = destx, xhi = destx + sizex - 1;
  182.   LONG ylo = desty, yhi = desty + sizey - 1;
  183.   if (xlo < CLP_xmin) xlo = CLP_xmin;
  184.   if (ylo < CLP_ymin) ylo = CLP_ymin;
  185.   if (xhi > CLP_xmax) xhi = CLP_xmax;
  186.   if (yhi > CLP_ymax) yhi = CLP_ymax;
  187.   if (xlo <= xhi && ylo <= yhi && 
  188.       xlo >= CLP_xmin && xhi <= CLP_xmax && 
  189.       ylo >= CLP_ymin && yhi <= CLP_ymax)
  190.     {
  191.       BltBitMapRastPort (srcbm, srcx + (xlo - destx), srcy + (ylo - desty),
  192.              destrp, xlo, ylo,
  193.              (xhi - xlo) + 1, (yhi - ylo) + 1,
  194.              minterm);
  195.     }
  196. }
  197. /*********/
  198.  
  199. /****** safeclip.h/SafeBltMaskBitMapRastPort
  200. * NAME
  201. *   SafeBltMaskBitMapRastPort
  202. * SYNOPSIS
  203. *        SafeBltMaskBitMapRastPort (srcbm, srcx, srcy,
  204. *                               destrp, destx, desty.
  205. *                               sizex, sizey, minterm, bltmask)
  206. *   VOID SafeBltMaskBitMapRastPort (struct BitMap *, LONG, LONG,
  207. *                               struct RastPort *, LONG, LONG,
  208. *                               LONG, LONG, UBYTE, PLANEPTR)
  209. * FUNCTION
  210. *   Blit a rectangle region from a BitMap to a RastPort through
  211. *   a single plane mask.
  212. * INPUTS
  213. *   srcbm - Pointer to source BitMap
  214. *   (srcx,srcy) - Coordinates of upper left of source rectangle.
  215. *   destrp - Pointer to destination RastPort
  216. *   (destx,desty) - Coordinates of upper left of destination rectangle.
  217. *   sizex, sizey - Size of source rectangle
  218. *   minterm - Minterm for blitter to use during copy
  219. *   bltmask - Pointer to single plane mask
  220. * RESULTS
  221. * SEE ALSO
  222. *   SafeBltBitMapRastPort
  223. */
  224. static __inline VOID
  225. SafeBltMaskBitMapRastPort (struct BitMap *srcbm, LONG srcx, LONG srcy,
  226.                struct RastPort *destrp, LONG destx, LONG desty,
  227.                LONG sizex, LONG sizey, UBYTE minterm, PLANEPTR bltmask)
  228. {
  229.   extern LONG CLP_xmin, CLP_xmax, CLP_ymin, CLP_ymax;
  230.   LONG xlo = destx, xhi = destx + sizex - 1, ylo = desty, yhi = desty + sizey - 1;
  231.   if (xlo < CLP_xmin) xlo = CLP_xmin;
  232.   if (ylo < CLP_ymin) ylo = CLP_ymin;
  233.   if (xhi > CLP_xmax) xhi = CLP_xmax;
  234.   if (yhi > CLP_ymax) yhi = CLP_ymax;
  235.   if (xlo <= xhi && ylo <= yhi && 
  236.       xlo >= CLP_xmin && xhi <= CLP_xmax && 
  237.       ylo >= CLP_ymin && yhi <= CLP_ymax)
  238.     {
  239.       BltMaskBitMapRastPort (srcbm, srcx + (xlo - destx), srcy + (ylo - desty),
  240.                  destrp, xlo, ylo,
  241.                  (xhi - xlo) + 1, (yhi - ylo) + 1,
  242.                  minterm, bltmask);
  243.     }
  244. }
  245. /*********/
  246.  
  247.